<?php
namespace Blog\Controller;
use Common\Controller\AdminbaseController;
use Org\Util\ArrayList;

class IndexadminController extends AdminbaseController{
    

    function index(){//游学网站
        $this->display();
    }
    function login(){//用户组
         $where=array();
        $request=I('request.');

        if(!empty($request['uid'])){
            $where['id']=intval($request['uid']);
        }

        if(!empty($request['keyword'])){
            $keyword=$request['keyword'];
            $keyword_complex=array();
            $keyword_complex['user_login']  = array('like', "%$keyword%");
            $keyword_complex['user_nicename']  = array('like',"%$keyword%");
            $keyword_complex['user_email']  = array('like',"%$keyword%");
            $keyword_complex['_logic'] = 'or';
            $where['_complex'] = $keyword_complex;
        }

        $users_model=M("User");

        $count=$users_model->where($where)->count();
        $page = $this->page($count, 20);

        $list = $users_model
            ->where($where)
            ->order("create_time DESC")
            ->limit($page->firstRow . ',' . $page->listRows)
            ->select();

        $this->assign('list', $list);
        $this->assign("page", $page->show('Admin'));

        $this->display();
    }
    // 管理员删除
    function delete(){
        $id = I('get.id',0,'intval');

        if ($this->users_model->delete($id)!==false) {
            M("user")->where(array("id"=>$id))->delete();
            $this->success("删除成功！");
        } else {
            $this->error("删除失败！");
        }
    }
    function Countrylist(){//游学国家列表
//        $where = array();
//        /**搜索条件**/
//        $Country_id = I('request.Country_id');
//        $Country = trim(I('request.Country'));
//        if($Country_id){
//            $where['Country_id'] = array('like',"%$Country_id%");
//        }
//
//        if($Country){
//            $where['Country'] = array('like',"%$Country%");;
//        }
//        $gj=M('country');
//
//        $count=$gj->where($where)->count();
//        $page = $this->page($count, 20);
//        $users = $gj
//            ->where($where)
//            ->order("create_time DESC")
//            ->limit($page->firstRow, $page->listRows)
//            ->select();
//        $roles_src=$this->role_model->select();
//        $roles=array();
//        foreach ($roles_src as $r){
//            $roleid=$r['id'];
//            $roles["$roleid"]=$r;
//        }
//        $this->assign("page", $page->show('Admin'));
//        $this->assign("roles",$roles);
//        $this->assign("users",$users);

        $this->display();
    }
    function StudySeries(){//游学系列
        $this->display();
    }
    function PersonalCenter(){//个人中心
        $this->display();
    }
    function Departuretime(){//出发时期
        $this->display();
    }
    function CityGroup(){//出团城市
        $this->display();
    }
    function Linedetails(){//线路详情
        $this->display();
    }
    function Travelsafety(){//个人中心->游学安全视频

    }
    function Appointment(){//个人中心->预约报名

    }
    function Offlinepayment(){//个人中心->线下订单支付/绑定

    }
    function Myorder(){//个人中心->我的订单


    }

    function add_xy(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =     './public/'; // 设置附件上传根目录
        $upload->savePath  =     'images/'; // 设置附件上传（子）目录
        $upload->saveName  =     array('uniqid', array('', true));

        // 上传文件
        $info   =   $upload->upload(array($_FILES['img']));
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功
            $condition = array();

            $name=I("xl_Title");
            $xq=I("Title_xq");
            $money=I("money");
            $cf = I("cf_city");
            $lx = I("xl_type");
            $zss = I("zs_object");
            $jz = I("jzDate");
            $user = M('Study_tour');


            $zs=I("zs");
            $xc_content=I("xc_content");
            $xc = M('xc');


                $condition['xl_Title'] = $name;
                $condition['Title_xq'] = $xq;
                $condition['money'] = $money;
                $condition['cf_city'] = $cf;
                $condition['xl_type'] = $lx;
                $condition['zs_object'] = $zss;
                $condition['jzDate'] = $jz;
                $condition['yximg'] =$info[0]['savepath'].$info[0]['savename'];

                 }

            if ($name == null){
                $this->error("标题不能为空！");
            }else{
                $id = $user->add($condition);
                if(empty($id)){
                    $this->error("错误！");
                }else{

                    $list = array();
                    foreach (I('post.day') as $k => $v){
                        $list[$k] = array(
                            'day'   => $v,
                            'zs'    => $zs[$k],
                            'xc_content'    => $xc_content[$k],
                            'ggid'  =>$id,
                            'img_1' =>$info[$k]['savepath'].$info[$k]['savename'],
                            'img_2' =>$info[$k]['savepath'].$info[$k]['savename'],
                        );
                        $xc->add($list[$k]);
                    }
//              添加亮点
                    $nr=I("ld_content");
                    $xcld = M('xcld');

                    $li = array();
                    foreach (I('xc_Title') as $k => $v){
                        $li[$k] = array(
                            'xc_Title' => $v,
                            'ld_content' =>$nr[$k],
                            'gid' =>$id,
                        );
                        $xcld->add($li[$k]);
                    }
                    $this->success("添加成功！");

                }

            }


            }


    
    }
